﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Library;


namespace SimulationGame
{
	public class TileMap
	{
		Tile[,] tiles;

		public int width;
		public int height;
		public List<Tile> tilesMarked = new List<Tile>();
		public bool isMouseDrawing = true;

		public TileMap(int width, int height,int resourcesAmount)
		{
			tiles = new Tile[width, height];
			this.width = width;
			this.height = height;
		}
		public Tile getTile(int x, int y)
		{
			return tiles[x, y];
		}
		public void HandleInput(InputState inputState)
		{
			if (inputState.IsMouseRightButtonPressed() && inputState.MousePosition.X> 0 && inputState.MousePosition.Y > 0 && tiles[(int)inputState.MousePosition.X / 32, (int)inputState.MousePosition.Y/32] != null)
			{
				tiles[(int)inputState.MousePosition.X / 32, (int)inputState.MousePosition.Y / 32].Mark(isMouseDrawing);
			}
			if (inputState.IsMouseRightButtonNewReleased())
			{
				if (isMouseDrawing)
				{
					isMouseDrawing = false;
				}
				else
				{
					isMouseDrawing = true;
				}
			}
		}
		public void Generate()
		{
			for (int x = 0; x < width; x++)
			{
				for (int y = 0; y < height; y++)
				{
					if (y < 10)
					{
						tiles[x, y] = TileRegistry.GetTileOfType("Air");
					}
					else
					{
						tiles[x, y] = TileRegistry.GetTileOfType("Ground");
					}
					tiles[x, y].position = new Vector2(x * 32, y * 32);
				}
			}
		}
	}
}
